//
//  WLRouterRestartView.m
//  WanLian
//
//  Created by muzhuang on 2018/11/19.
//  Copyright © 2018年 wanlian. All rights reserved.
//

#import "WLRouterRestartView.h"

@implementation WLRouterRestartView

- (instancetype)init
{
    self = [super init];
    if (self) {
        CGFloat width = 300.0;///WIDTH_SCREEN_WL-WLScaleX(72);
        _alert = [[UIView alloc]initWithFrame:CGRectMake((WIDTH_SCREEN_WL-width)/2.0, (HEIGHT_SCREEN_WL-200.0)/2.0, width, 200)];
        _alert.backgroundColor = wlUIColorRGB(0xFAFAFA);
        [self addSubview:_alert];
        _alert.layer.cornerRadius = 5;
        _alert.layer.masksToBounds = YES;
        
        self.frame = [[UIScreen mainScreen]bounds];
        self.backgroundColor = wlRGBACOLOR(0, 0, 0, 0.5);
        
        UILabel *labTip = [[UILabel alloc]initWithFrame:CGRectMake(5, 25, width-10, 25)];
        labTip.text = @"提示";
        labTip.textColor = wlBlackColor;
        labTip.textAlignment = NSTextAlignmentCenter;
        labTip.font = [WLCommonTool fontTypePingFangSCMedium:17];
        [_alert addSubview:labTip];
        
//        UIImageView *ivTip = [[UIImageView alloc] initWithFrame:CGRectMake((width-45.0)/2.0, 50+10, 45, 44)];
//        ivTip.image = [UIImage imageNamed:@"restart_indicator"];
//        [_alert addSubview:ivTip];
        UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
        [_alert addSubview:activityIndicator];
//        activityIndicator.center = CGPointMake(100.0f, 100.0f);
        //设置小菊花的frame
        activityIndicator.frame= CGRectMake((width-45.0)/2.0, 50+10, 45, 45);
        //设置小菊花颜色
        activityIndicator.color = wlUIColorRGB(0xD8D8D8);
        [activityIndicator startAnimating];
        
        UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(5, 50+10+45+12, width-10, 20)];
        titleLabel.text = @"配置生效中，路由器正在重新启动";
        titleLabel.textColor = wlDarkGrayColor;
        titleLabel.textAlignment = NSTextAlignmentCenter;
        titleLabel.font = [WLCommonTool fontTypePingFangSCRegular:14];
        [_alert addSubview:titleLabel];
        
        UIView *henV = [[UIView alloc]initWithFrame:CGRectMake(0, 200-45, width, 1)];
        henV.backgroundColor = wlUIColorRGB(0xF2F2F2);
        [_alert addSubview:henV];
        
        UIButton *sureBtn = [[UIButton alloc] initWithFrame:CGRectMake(10, 200-44, width-20, 44)];
        sureBtn.titleLabel.font = [WLCommonTool fontTypePingFangSCMedium:17];
        [sureBtn setTitle:@"确认" forState:UIControlStateNormal];
        [sureBtn setTitleColor:wlUIColorRGB(0x29A8FA) forState:UIControlStateNormal];
        [sureBtn addTarget:self action:@selector(sureClick) forControlEvents:UIControlEventTouchUpInside];
        [_alert addSubview:sureBtn];
    }
    return self;
}

- (void)cancelClick
{
    [self hide];
}

- (void)sureClick
{
    if (self.okAction) {
        self.okAction();
    }
    [self hide];
}

- (void)show
{
    if (self.superview==nil) {
        UIWindow *window =  [[UIApplication sharedApplication].windows firstObject];
        [window addSubview:self];
    }
    
    self.alpha = 0;
    _alert.transform = CGAffineTransformScale(_alert.transform,0.1,0.1);
    WLWkSelf
    [UIView animateWithDuration:0.25 animations:^{
        weakSelf.alert.transform = CGAffineTransformIdentity;
        self.alpha = 1;
    }];
}

- (void)hide
{
    if (self.superview) {
        WLWkSelf
        [UIView animateWithDuration:0.25 animations:^{
            weakSelf.alert.transform = CGAffineTransformScale(weakSelf.alert.transform,0.1,0.1);
            self.alpha = 0;
        } completion:^(BOOL finished) {
            [self removeFromSuperview];
        }];
    }
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
